home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / UTILS / AMOSPRO4.DMS / in.adf / Tutorials / Procedures_1.AMOS / Procedures_1.amosSourceCode
Encoding:
AMOS Source Code  |  1992-09-28  |  5.1 KB  |  184 lines

  1. '*************************** 
  2. '*    AMOS Professional    *             INSTRUCTIONS COVERED
  3. '*                         * 
  4. '*       PROCEDURES 1      *                  Procedure  
  5. '*                         *                  End Proc 
  6. '* (c) Europress Software  *                  Proc 
  7. '*                         * 
  8. '*     Ronnie Simpson      * 
  9. '*************************** 
  10. '
  11. '------------------------------------------- 
  12. 'GENERAL 
  13. '------------------------------------------- 
  14. 'Procedures allow a program to be developed in small 'modules' which can be
  15. 'easily tested and de-bugged individually without getting bogged down in 
  16. 'lengthy lists of code.
  17. 'They have several advantages over the alternative subroutine and each can 
  18. 'have its own set of variables,data lists and program lines which are
  19. 'independant of the main program and other procedures. 
  20. 'Once you have mastered the basics of working with procedures then I am sure 
  21. 'that most of your future programming will make liberal use of these 
  22. 'powerful aids.  
  23. '------------------------------------------- 
  24. 'Setting up a simple procedure 
  25. '------------------------------------------- 
  26. '           Procedure NAME 
  27. '               :      : 
  28. '               :      : 
  29. '           End Proc 
  30. '
  31. 'A procedure is identified by giving it a name, this can be any legal string 
  32. 'of characters just like your variables. 
  33. 'Each procedure must be terminated by the instruction End Proc.
  34. 'Both 'Procedure' and 'End Proc must be given their own individual lines.
  35. 'Everything inside the procedure will be ignored by the program until the
  36. 'procedure is called, this is done by entering the procedure name at any 
  37. 'point in the program. 
  38. '
  39. 'eg.           WARNING 
  40. '              ' 
  41. '              Procedure WARNING 
  42. '              Print "smoking can damage your health"
  43. '              End Proc
  44. '
  45. 'To avoid any confusion the optional 'Proc' instruction may be used. 
  46. '
  47. 'eg            Proc WARNING
  48. '
  49. 'Always leave a space between the procedure name and the colon when using
  50. 'multi-statemaent lines or the instruction will be interpreted as a lable. 
  51. '
  52. 'eg.    WARNING: Print "incorrect"   (this would define the lable WARNING) 
  53. '       WARNING : Print "correct"    (this would call the procedure) 
  54. '
  55. '------------------------------------------- 
  56. 'Procedure variables 
  57. '------------------------------------------- 
  58. 'Normally all variables used in a procedure are 'local' or independant from
  59. 'the rest of the program, it is therfore perfectly feasible to have
  60. 'the same variable name with 2 to more different values in the same program  
  61. 'depending on whether they are inside or outside the procedures. 
  62. '
  63. 'eg        A=100 
  64. '          Proc REDHERRING 
  65. '          Proc REDHERRING 
  66. '          Print A 
  67. '          Print C 
  68. '          End 
  69. '          ' 
  70. '          Procedure REDHERRING
  71. '          B=200 : C=A+B 
  72. '          Print C 
  73. '          End Proc
  74. 'Try to work out what the 4 values are that would be printed if this program 
  75. 'was run, bearing in mind that:- 
  76. '     (1) 'A' and 'C' can have  different values inside the procedure. 
  77. '     (2) 'B' and 'C' are local variables to the procedure 
  78. '     (3) Local variables are flushed (assigned a value of zero) each time 
  79. '         the procedure is used. 
  80. '
  81. 'Answer at line 179 at the bottom of this listing. 
  82. '
  83. 'There are ways you can transfer information to and from a procedure and 
  84. 'these are dealt with in the Procedures_2 tutorial.
  85. '
  86. '------------------------------------------- ' 
  87. 'WORKING EXAMPLE 
  88. '------------------------------------------- 
  89. Rem *** set out screen 
  90. '
  91. Screen Open 0,640,200,16,Hires : Flash Off : Hide 
  92. Palette $0,$F00,$F0,$F,$FF0,$F0F,$FF,$F70,$7F,$70F,$F07,$333,$666,$999,$CCC,$FFF
  93. Curs Off : Cls 0 : Paper 0 : Pen 6
  94. Locate 1,1 : Centre Border$("A PROVERB A DAY KEEPS THE DOCTOR AWAY!",3)
  95. Locate 0,20 : Centre "LEFT MOUSE KEY FOR ANOTHER PROVERB       RIGHT MOUSE KEY TO QUIT"
  96. '
  97. '
  98. Rem *** start main loop
  99. '
  100. Do 
  101. '
  102. '
  103. Rem *** call the 3 procedures
  104. '
  105. Proc BEGINING
  106. Proc MIDDLE
  107. Proc FINISH
  108. '
  109. '
  110. Rem *** wait for a mouse click 
  111. '
  112. Wait 50
  113. Do 
  114. M=Mouse Key
  115. Exit If M
  116. Loop 
  117. Exit If M=2
  118. '
  119. '
  120. Rem *** clear the old proverb and repeat or quit 
  121. Cline 
  122. Loop 
  123. Edit 
  124. '
  125. '
  126. Rem *** the procedures 
  127. '
  128. Procedure BEGINING
  129. Pen(Rnd(9)+1)
  130. Locate Rnd(15)+5,Rnd(12)+5
  131. R=Rnd(8)+1 : Restore(R)
  132. Read A$
  133. Print A$+" ";
  134. 1 Data "A ROLLING STONE"
  135. 2 Data "A STITCH"
  136. 3 Data "A BIRD IN THE HAND"
  137. 4 Data "ALL THAT GLITTERS"
  138. 5 Data "EVERY CLOUD"
  139. 6 Data "TOO MANY COOKS"
  140. 7 Data "TIME AND TIDE"
  141. 8 Data "PEOPLE IN GLASS HOUSES"
  142. 9 Data "THE PEN"
  143. 10 Data "NECESSITY"
  144. End Proc
  145. '
  146. Procedure MIDDLE
  147. R=Rnd(9)+1 : Restore(R+10)
  148. Read A$
  149. Print A$+" ";
  150. 11 Data "GATHERS NO"
  151. 12 Data "IN TIME SAVES"
  152. 13 Data "IS WORTH 2 IN THE"
  153. 14 Data "IS NOT"
  154. 15 Data "HAS A SILVER"
  155. 16 Data "SPOILS THE"
  156. 17 Data "WAITS FOR NO"
  157. 18 Data "SHOULD NOT THROW"
  158. 19 Data "IS MIGHTIER THAN THE"
  159. 20 Data "IS THE MOTHER OF"
  160. End Proc
  161. '
  162. Procedure FINISH
  163. R=Rnd(9)+1 : Restore(R+20)
  164. Read A$
  165. Print A$+" ";
  166. 21 Data "MOSS"
  167. 22 Data "NINE"
  168. 23 Data "BUSH"
  169. 24 Data "GOLD"
  170. 25 Data "LINING"
  171. 26 Data "BROTH"
  172. 27 Data "MAN"
  173. 28 Data "STONES"
  174. 29 Data "SWORD"
  175. 30 Data "INVENTION"
  176. End Proc
  177. '
  178. '--------------------
  179. 'answer to problem:- 
  180. '       200  
  181. '       200  
  182. '       100  
  183. '       0  
  184. '--------------------